package com.sky.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.sky.dto.TUserDTO;
import com.sky.dto.UserPageQueryDTO;
import com.sky.entity.TUser;
import com.sky.mapper.TUserMapper;
import com.sky.result.PageResult;
import com.sky.service.TUserService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class TUserServiceImpl implements TUserService {


    @Autowired
    private TUserMapper tUserMapper;

    /**
     * 分页查询用户
     * @param userPageQueryDTO
     * @return
     */
    public PageResult pageQuery(UserPageQueryDTO userPageQueryDTO) {
        PageHelper.startPage(userPageQueryDTO.getPage(), userPageQueryDTO.getPageSize());

        Page<TUser> page =tUserMapper.pageQuery(userPageQueryDTO);

        Long total = page.getTotal();
        List<TUser> list = page.getResult();

        return new PageResult(total, list);
    }

    /**
     * 根据id查询用户
     * @param id
     * @return
     */
    public TUser getUserById(Long id) {
        TUser tUser = tUserMapper.getById(id);
        return tUser;
    }

    /**
     * 更新用户信息
     * @param tUserDTO
     */
    public void updateUser(TUserDTO tUserDTO) {
        TUser tuser=new TUser();
        BeanUtils.copyProperties(tUserDTO,tuser);

        tUserMapper.update(tuser);
    }
}
